/**
 * 
 */
package com.johnny.xia.filetest;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author johnnyxia
 *
 */
public class LogMerge{

    public static void main(String[] args){
        
    }
    
    /**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    public static Map<String,List<String>> readFileByLines(String fileName){

        Map<String,List<String>> map = new HashMap<>();
        
        StringBuffer buffer = new StringBuffer();

        File file = new File(fileName);
        BufferedReader reader = null;
        try{
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null){
                
                String[] array = tempString.split(" \\(");
                
                if(map.get(array[0]) == null){
                    List<String> list = new ArrayList<>();
                    list.add(array[1]);
                    map.put(array[0], list);
                }else{
                    map.get(array[0]).add(array[1]);
                }
            }
            reader.close();
        }catch (IOException e){
            e.printStackTrace();
        }finally{
            if (reader != null){
                try{
                    reader.close();
                }catch (IOException e1){}
            }
        }
        return map;
    }
}
